package net.zjitc.lib.Share.wait;

/**
 * 作业使用Handle 与 Thread 下载网络图片  显示出来
 */
public class Quene {
    private volatile int n;

    public synchronized int get() {
        if (n == 0) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        notify();
        System.out.println("Get:" + this.n);
        n=n-1;
        return n;
    }

    public synchronized void put(int n1) {
//        this.n = n;
        if (this.n==n1+1){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        this.n=n+1;
        notify();
        System.out.println("Put:" + this.n);
    }
}
